package dictcn.com.control;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

//本地数据库操作类
public class MyDatabaseHelper extends SQLiteOpenHelper {
	
	//本地数据库
	private static final String DATABASENAME_FOR="dict.db";
	
	//数据库版本号
	private static final int DATABASEVERSION=1;
	
	//常用单词记录表
	private static final String TABLE_BOOK ="book";
	
	//本地生词本记录表
	private static final String TABLE_BOOKNAME="bookname";
	
	//本地生词本生词表
	private static final String TABLE_LOCALLIBRARY ="locallibrary";
	
	//扩展离线包数据信息表
	private static final String TABLE_PACKAGE ="package";
	
	//热词表
	private static final String TABLE_RECI ="rici";
	
	
	public MyDatabaseHelper(Context context) {
		// TODO Auto-generated constructor stub
		super(context,DATABASENAME_FOR,null,DATABASEVERSION);
	}
	
	//建立相应的数据表
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		String sql1="CREATE TABLE "+TABLE_BOOK+"(" +
			"mbid    INTEGER 	PRIMARY KEY AUTOINCREMENT NOT NULL,"+
			"b_id    INTEGER 	NOT NULL,"+
			"l_id    INTEGER 	NOT NULL,"+
			"t_time  TEXT 		NOT NULL,"+
			"xingji  INTEGER 	NOT NULL);";
		db.execSQL(sql1);
		
		String sql2="CREATE TABLE "+TABLE_BOOKNAME+"(" +
			"b_id   	INTEGER 	PRIMARY KEY AUTOINCREMENT NOT NULL,"+
			"b_name  	TEXT 		NOT NULL,"+
			"count  	INTEGER 	NOT NULL)";
		db.execSQL(sql2);
		
		String sql3="CREATE TABLE "+TABLE_LOCALLIBRARY+"(" +
			"l_id  			INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"+
			"letter_name  	TEXT 	NOT NULL,"+
			"interpret  	TEXT,"+
			"fayin_en  		TEXT,"+
			"fayin_am  		TEXT,"+
			"sign  			INTEGER,"+
			"pinyin  		TEXT)";
		db.execSQL(sql3);
		
		String sql4="CREATE TABLE "+TABLE_PACKAGE+"(" +
			"p_id  		INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"+
			"p_name 	TEXT 	NOT NULL,"+
			"p_num  	TEXT 	NOT NULL,"+
			"price  	TEXT 	NOT NULL,"+
			"p_record  	TEXT 	NOT NULL,"+
			"note  		TEXT 	NOT NULL)";
		db.execSQL(sql4);
		
		String sql5="CREATE TABLE "+TABLE_RECI+"(" +
			"re_id  	INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"+
			"re_chname  TEXT 	NOT NULL,"+
			"re_enname  TEXT 	NOT NULL,"+
			"re_image  	TEXT,"+
			"re_time  	TEXT 	NOT NULL,"+
			"content  	TEXT 	NOT NULL)";
		db.execSQL(sql5);
				
	}	
	
	//更新数据表
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		String sql1="DROP TABLE IF EXISTS "+TABLE_BOOK;
		db.execSQL(sql1);
		
		String sql2="DROP TABLE IF EXISTS "+TABLE_BOOKNAME;
		db.execSQL(sql2);
		
		String sql3="DROP TABLE IF EXISTS "+TABLE_LOCALLIBRARY;
		db.execSQL(sql3);
		
		String sql4="DROP TABLE IF EXISTS "+TABLE_PACKAGE;
		db.execSQL(sql4);
		
		String sql5="DROP TABLE IF EXISTS "+TABLE_RECI;
		db.execSQL(sql5);
		
		this.onCreate(db);
	}
}
